Namespace Component

    ''' <summary>
    ''' General software about dialog in VS2005 style.
    ''' </summary>
    ''' <remarks></remarks>
    Public Class AboutDialog

        Private WithEvents m_MainWnd As Windows.Forms.Form
        Private Const CST_TITLEANDSUBTITLE_PADDING As Integer = 0
        Private Const CST_SHADOW_OFFSET As Integer = 4

        ''' <summary>
        ''' Get or set the form text property.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Caption() As String
            Get
                Return Me.Text
            End Get
            Set(ByVal value As String)
                Me.Text = "About " & value
            End Set
        End Property

        ''' <summary>
        ''' Get or set the company name in header field.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Company() As String
            Get
                Return Me.lblCompany.Text
            End Get
            Set(ByVal value As String)
                Me.lblCompany.Text = value & ChrW(169)
            End Set
        End Property

        ''' <summary>
        ''' Get or set the software title in header field.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Title() As String
            Get
                Return Me.lblTitle.Text
            End Get
            Set(ByVal value As String)
                Me.lblTitle.Text = value
            End Set
        End Property

        ''' <summary>
        ''' Get or set the software sub-title in header field.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property SubTitle() As String
            Get
                Return Me.lblSubTitle.Text
            End Get
            Set(ByVal value As String)
                Me.lblSubTitle.Text = value
            End Set
        End Property

        ''' <summary>
        ''' Get or set the software full name in doay field.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property SoftwareName() As String
            Get
                Return Me.lblSoftwareName.Text
            End Get
            Set(ByVal value As String)
                Me.lblSoftwareName.Text = value
            End Set
        End Property

        ''' <summary>
        ''' Get or set the register user name.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Registed() As String
            Get
                Return Me.lblRegsterUser.Text
            End Get
            Set(ByVal value As String)
                Me.lblRegsterUser.Text = value
            End Set
        End Property

        ''' <summary>
        ''' Get or set the version information.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Version() As String
            Get
                Return Me.lblVersion.Text
            End Get
            Set(ByVal value As String)
                Me.lblVersion.Text = value
            End Set
        End Property

        ''' <summary>
        ''' Get or set the copyright information.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Copyright() As String
            Get
                Return Me.lblCopyright.Text
            End Get
            Set(ByVal value As String)
                Me.lblCopyright.Text = value
            End Set
        End Property

        ''' <summary>
        ''' Get or set the product icon.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks>The icon size is 64*64.</remarks>
        Public Property ProductIcon() As Drawing.Image
            Get
                Return Me.picIcon.BackgroundImage
            End Get
            Set(ByVal value As Drawing.Image)
                Me.picIcon.BackgroundImage = value
            End Set
        End Property

        ''' <summary>
        ''' Get or set Addtion component name.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property AddtionName() As String
            Get
                Return Me.lblAddtionName.Text
            End Get
            Set(ByVal value As String)
                Me.lblAddtionName.Text = value
            End Set
        End Property

        ''' <summary>
        ''' Get or set Addtion component version.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property AddtionVersion() As String
            Get
                Return Me.lblAddtionVersion.Text
            End Get
            Set(ByVal value As String)
                Me.lblAddtionVersion.Text = value
            End Set
        End Property

        Public Sub New()

            ' This call is required by the Windows Form Designer.
            InitializeComponent()

            ' Add any initialization after the InitializeComponent() call.
        End Sub

        Public Sub Initialize(ByVal AssInfo As ApplicationServices.AssemblyInfo, ByVal ExcludeAssList() As String)
            Dim ass As Reflection.Assembly
            Dim lvi As Windows.Forms.ListViewItem
            'Set the head field company name and software title
            Company = AssInfo.CompanyName
            Title = AssInfo.Title
            'Clear register infomation
            Registed = String.Empty
            'Set the version and clear copyright
            Version = AssInfo.Version.ToString
            Copyright = String.Empty
            'Display assemblies
            Me.lvProducts.BeginUpdate()
            Me.lvProducts.Items.Clear()
            For Each ass In AssInfo.LoadedAssemblies
                If ass.GetName.Name = AssInfo.AssemblyName OrElse Array.IndexOf(ExcludeAssList, ass.GetName.Name) >= 0 Then
                Else
                    lvi = New Windows.Forms.ListViewItem(ass.GetName.Name)
                    lvi.SubItems.Add(ass.GetName.Version.ToString)
                    Me.lvProducts.Items.Add(lvi)
                End If
            Next
            Me.lvProducts.Sorting = Windows.Forms.SortOrder.Ascending
            Me.lvProducts.Sort()
            Me.lvProducts.EndUpdate()
        End Sub

        Public Sub ExecutePerformLayout()
            Me.lblSubTitle.Left = Me.lblTitle.Left + Me.lblTitle.Width + CST_TITLEANDSUBTITLE_PADDING
        End Sub

        Private Sub pnlHeader_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pnlHeader.Paint
            Me.DrawSoftwareTitleInSadows(e.Graphics)
        End Sub

        Private Sub DrawSoftwareTitleInSadows(ByVal g As Drawing.Graphics)
            g.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
            'Draw Title
            g.DrawString(Me.lblTitle.Text, Me.lblTitle.Font, Drawing.Brushes.DarkGray, Me.lblTitle.Left + CST_SHADOW_OFFSET, Me.lblTitle.Top + CST_SHADOW_OFFSET)
            g.DrawString(Me.lblTitle.Text, Me.lblTitle.Font, Drawing.Brushes.Black, Me.lblTitle.Left, Me.lblTitle.Top)
            'Draw Sub Title
            g.DrawString(Me.lblSubTitle.Text, Me.lblSubTitle.Font, Drawing.Brushes.DarkGray, Me.lblSubTitle.Left + CST_SHADOW_OFFSET, Me.lblSubTitle.Top + CST_SHADOW_OFFSET)
            g.DrawString(Me.lblSubTitle.Text, Me.lblSubTitle.Font, Drawing.Brushes.Black, Me.lblSubTitle.Left, Me.lblSubTitle.Top)
        End Sub

    End Class

End Namespace
